<%@ page language="java" import="java.sql.*" %>
<HTML>   
<HEAD><TITLE>Welcome</TITLE></HEAD>  
<BODY>

<%
	String user="";
	Connection conn=null;
	Statement st=null;

	String url = "jdbc:oracle:thin:@localhost:1521";
	String dbName = ":orcl";
	String driver = "oracle.jdbc.driver.OracleDriver";
	String userName = "scott"; 
	String password = "tiger";
	
	try{
		Class.forName(driver).newInstance();
		}catch(ClassNotFoundException e){
		e.printStackTrace();
		}	
		try{
			conn = DriverManager.getConnection(url+dbName,userName,password);
			st=conn.createStatement();
		}catch(SQLException e){
			e.printStackTrace();
		}catch(Exception e){
			e.printStackTrace();
		}
if(session.getAttribute("username")!=null && session.getAttribute("username")!="")
{
	user = session.getAttribute("username").toString();
%>
<table align=center border=0>
<tr><td align="center">Welcome <b><%= user%></td></tr>
</table>
<table align="center" border=1>
<TR>
<TH>Parameter Name<TH>Parameter Value(s)</TR>
<%
}
		try{
			ResultSet rs=null;
			 rs=st.executeQuery("select * from Thermostat_Current_Information where username='"+user+"'");
			while(rs.next())
			{
				%>
				<form name="loginform" method="post" action="/Thermostat/Update_Thermostat">
				<tr><td><b>Current_Temperature</td><td>
				<select name="current_temperature" >
				<% int i; for (i=70;i<90;i++){ 
				if(i==Integer.parseInt(rs.getString(1)))
				{%>
				<option value=<%=i%> selected="selected"><%=i%></option>
				<%}
				else
				{	
				%>
				<option value=<%=i%>><%=i%></option>
				<%}}%>
				</select>
				</td></tr>
				<tr><td><b>Thermostat Operating Mode</td><td>
				<select name="op_mode" >
				<% int j; for (j=0;j<4;j++){ 
				String mode="";
				if(j==0)
					mode="Off";
					else if(j==1)
					mode="Heat";
					else if(j==2)
					mode="Cool";
					else
					mode="Auto";
				if(j==Integer.parseInt(rs.getString(2)))
				{	
				%>
				<option value=<%=j%> selected="selected"><%=mode%></option>
				<%}
				else
				{
				%>
				<option value=<%=j%>><%=mode%></option>
				<%}}%>
				</select>
				</td></tr>
				<tr><td><b>Fan Operating ModeMode</td><td>
				<select name="fan_op_mode" >
				<% int k; for (k=0;k<3;k++){ 
				String fmode="";
				if(k==0)
					fmode="Auto";
					else if(k==1)
					fmode="Circulate";
					else if(k==2)
					fmode="On";
				if(k==Integer.parseInt(rs.getString(3)))
				{	
				%>
				<option value=<%=k%> selected="selected"><%=fmode%></option>
				<%}
				else
				{
				%>
				<option value=<%=k%>><%=fmode%></option>
				<%}}%>
				</select>
				</td></tr>
				<tr><td><b>Target Temperature</td><td>
				<select name="target_temperature" >
				<% int m; for (m=70;m<90;m++){ 
				if(m==Integer.parseInt(rs.getString(4)))
				{%>
				<option value=<%=m%> selected="selected"><%=m%></option>
				<%}
				else
				{
				%>
				<option value=<%=m%>><%=m%></option>
				<%}}%>
				</select></td></tr>
				</table>
				<table align="center" border=0>
				<tr><td><input type="submit" name="Submit" value="Update"></td></tr>
				</table>
				</form>
				<%
			}
			rs.close();
		    }catch(SQLException e){
			e.printStackTrace();
		    }
			
		try{
			if(conn!=null)
			conn.close();
		}catch(SQLException e){
			e.printStackTrace();
		}

%>
<table align=center>
<form name=view action="">
<tr><td>
<a href="welcome.jsp">Go to Main Page</a>
</td></tr>
</form>
</table>

</body>
<html>


